﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
namespace libCommonTools.Forms
{
    public partial class frmFindGRN : Telerik.WinControls.UI.RadForm
    {
        private clsTimerDelay TimerDelay;
        public frmFindGRN()
        {
            InitializeComponent();
        }

        private void frmFindGRN_Load(object sender, EventArgs e)
        {
            ((GridTableElement)this.dgvFind.TableElement).RowHeight = 20;
            TimerDelay = new clsTimerDelay();
            set_GridColumns();
        }

        private void set_GridColumns()
        {
            try
            {
                dgvFind.Columns.Add("connoteno", "GRN No.");
                dgvFind.Columns.Add("shipname", "Shipper Name");
                dgvFind.Columns.Add("conname", "Consignee Name");
                dgvFind.Columns.Add("connotedate", "GRN Date");
                dgvFind.Columns.Add("shipinvno", "Invoice No.");
                dgvFind.Columns.Add("trastacode", "Status");
                dgvFind.Columns.Add("stickno", "Sticker No.");
                dgvFind.Columns.Add("shipid", "Shipper ID");
                dgvFind.Columns.Add("conid", "Consignee ID");
                dgvFind.Columns.Add("refno", "Ref. No");
                dgvFind.Columns.Add("portid", "Port ID");
                dgvFind.Columns.Add("speins", "Shipping Instruction");
                dgvFind.Columns.Add("totqty", "Total QTY");
                dgvFind.Columns.Add("totcbm", "Total CBM");
                dgvFind.Columns.Add("totwei", "Total Weight");
                dgvFind.Columns.Add("issby", "Issued by");
                dgvFind.Columns.Add("vehplano", "Vehicle No.");
                dgvFind.Columns.Add("grntypecode", "Type");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GridColumns"); 
            }
        }

        private void set_Seach()
        {
            try
            {
                if (ddlFindBy.Text.Trim() != string.Empty)
                {
                    if (txtSearch.Text.Trim() != string.Empty && Convert.ToInt32(mskTop.Value) > 0)
                    {
                        if (txtSearch.Text.Length < 2)
                        {
                            TimerDelay.RevokeQueryTimer();
                        }
                        else
                        {
                            TimerDelay.RestartQueryTimer();
                        }
                    }
                }
                else
                {
                    dgvFind.Rows.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Seach");
            }
        }

        private void setSeachCriteriaDDl()
        {
            try
            {
                if (ddlFindBy.Items.Count > 0)
                {
                    ddlFindBy.Items.Clear();
                }
                for (int intColIndex = 0; intColIndex < dgvFind.Columns.Count; intColIndex++)
                {
                    if (dgvFind.Columns[intColIndex].HeaderText.Trim() != "comidHQ")
                    {
                        ddlFindBy.Items.Add(dgvFind.Columns[intColIndex].HeaderText.Trim());
                    }
                }
                ddlFindBy.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " setSeachCriteriaDDl");
            }
        }
    }
}
